<?php

namespace App\Http\Controllers\Mobile;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use DB;
class LoginController extends Controller
{
    public function login(Request $request){
        if(is_post()){
            return ['id'=>0];
            $input = $request->except('_token');
            if(empty($input['phone']) || empty($input['code'])){
                return ['id'=>1,'msg'=>'手机、验证码不能为空'];
            }
            if($input['phone'] != session('phone')){
                return ['id'=>1,'msg'=>'手机号错误'];
            }
            if($input['code'] == session('code')){
//                if (Auth::guard('users')->attempt(['wei_token' => session('wei_token')])) {
//                    // 认证通过...
//                    return ["Status"=>"ok","Text"=>"登陆成功<br /><br />欢迎回来"];
//                }
                return ['id'=>0];
            }else{
                return ['id'=>1,'msg'=>'验证码错误'];
            }
        }else{
            return view("mobile.login");
        }
    }
    public function sms(Request $request){
        $input = $request->except('_token');
        if(empty($input['phone'])){
            return ['error_code'=>1,'msg'=>'手机不能为空'];
        }
        $wahe_data = DB::table("wages")->where("phone",$input['phone'])->get()->toArray();
        if(!$wahe_data){
            return ['error_code'=>1,'msg'=>'未发现工资条'];
        }
        $code = rand(00000,999999);
        $nwecode = urlencode("#code#=".$code);
        session(['code'=>$code,'phone'=>$input['phone']]);
        $sms = file_get_contents("http://v.juhe.cn/sms/send?mobile=".$input['phone']."&tpl_id=47890&tpl_value=".$nwecode."&key=38d288ab03ca4ad5b792fc7bc7a8e994");
        echo $sms;
    }
    public function logout(){
//        Auth::guard('users')->logout();
        return ['id'=>0];
    }
}
